package logic.nodes.nodeSettings;

import fileHandling.language.Lang;

import java.util.HashMap;
import java.util.Set;

public abstract class AbstractSettings<T extends AbstractOption> {
	
	public static final String FLOAT_DELIMITER = ",";
	
	protected HashMap<String, T> optionMap;
	
	public AbstractSettings() {
		optionMap = new HashMap<String, T>();
	}
	
	public AbstractSettings(AbstractSettings<T> settings) {
		this();
		copySettings(settings, true);
	}
	
	public Set<String> getKeys() { return optionMap.keySet(); }
	
	public String getValueOf(Lang key) { return getValueOf(key.toString()); }
	
	public String getValueOf(String key) {
		T option = getOption(key);
		if(option == null) return null;
		return option.getValue();
	}
	
	protected T getOption(String key) { return optionMap.get(key); }
	
	public HashMap<String, T> getOptionMap() { return optionMap; }
	
	public void copySettings(AbstractSettings<T> settings, boolean reset) {
		if(optionMap == null || reset) optionMap = new HashMap<String, T>();
		optionMap.putAll(settings.getOptionMap());
	}
	
	public static float[] getFloatValues(String string) {
		String[] parts = string.split(FLOAT_DELIMITER);
		float[] values = new float[parts.length];
		for(int i = 0; i < parts.length; i++) {
			values[i] = Float.valueOf(parts[i]).floatValue();
		}
		return values;
	}
}